package com.charlotte.study.gupao.iterator.course;

import java.util.List;

/**
 * @author junjie.ding
 * @date 2020/3/16
 */
public class IteratorImpl<E> implements Iterator<E> {

    private List<E> list;

    private int cursor = 0;

    private E curElement;

    public IteratorImpl(List<E> list) {
        this.list = list;
    }

    @Override
    public E next() {
        this.curElement = this.list.get(this.cursor);
        this.cursor ++;
        return curElement;
    }

    @Override
    public boolean hasNext() {
        return this.cursor < this.list.size();
    }
}
